package com.wenx.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

import java.util.Date;

/**
 * 通过camel实现文件移动
 */
public class App3 extends RouteBuilder {

    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.addRoutes(new App3());
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }

    /**
     * 将log目录下的文件移动到logs下,文件夹不会移动
     * from("file:d:/temp/inbox/?delay=30000").to("jms:queue:order");
     * delay=30000是每隔30秒轮询一次文件夹中是否有文件.
     * @throws Exception
     */
    /*public void configure() throws Exception {
        from("file:d:/log/?delay=30000").to("file:d:/logs");
    }*/

    public void configure() throws Exception {
        from("file:d:/log/?delay=30000")
                .process(new FileMoveProcessor())
                .to("file:d:/logs");
    }

}